import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'
import type {
  GetFactorListParams,
  GetFactorListResult,
  GetFactorParams,
  GetFactorResult,
  IFactorAdd
} from './model/factorListModel'
import config from '@/config'

enum Api {
  // 因子库列表分页查询
  GET_FACTOR_LIST = '/footprint/factor/pageFactor',
  // 新建因子
  CREATE_FACTOR = '/footprint/factor/createFactor',
  EDIT_FACTOR = '/footprint/factor/editFactor',
  DEL_FACTOR = '/footprint/factor/deleteFactor',
  GET_FACTOR = '/footprint/factordb/factorLibrary/getInfoFactor',
  // 因子库文件导入
  IMPORT_FACTOR = '/footprint/factor/factorImport'
}

// 因子库列表分页查询
export const getFactorList = (
  params: GetFactorListParams & BasicPagingListParams
): Promise<BasicPagingListResult<GetFactorListResult>> => get(Api.GET_FACTOR_LIST, params)

export const addFactor = (params: IFactorAdd): Promise<void> => post(Api.CREATE_FACTOR, params)

export const delFactor = (factorNo: string): Promise<void> => post(Api.DEL_FACTOR, { factorNo })

export const editFactorDetail = (params: IFactorAdd): Promise<void> => post(Api.EDIT_FACTOR, params)

// 查询单个因子
export const getFactor = (params: GetFactorParams): Promise<GetFactorResult[]> =>
  get(Api.GET_FACTOR, params)

// 因子库导入url
export const importFactorUrl = config.BASE_URL + Api.IMPORT_FACTOR
